﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace Mozhi.Abp.Module.DataLinkage
{
    public class DataLinkageAppService : DataLinkageAppServiceBase, IDataLinkageAppService
    {
        private IDataLinkageRepository _repository;

        public DataLinkageAppService(IDataLinkageRepository repository)
        {
            _repository = repository;
        }

        public async Task<PagedResultDto<DataLinkageDto>> GetListAsync(DataLinkageResultRequestDto filter)
        {
            var dataLinkages = await _repository.GetPagedListAsync(filter.Keyword, filter.ProviderId, filter.ConsumerId, filter.SkipCount, filter.MaxResultCount, filter.Sorting);

            var count = await _repository.GetCountAsync(filter.Keyword, filter.ProviderId, filter.ConsumerId);

            var result = new PagedResultDto<DataLinkageDto>()
            {
                Items = ObjectMapper.Map<List<DataLinkage>, List<DataLinkageDto>>(dataLinkages),
                TotalCount = count
            };

            return result;
        }

        
    }
}
